package com.ict.ms.trackPlayBack.service.api.impl;

import com.ict.ms.trackPlayBack.facade.common.AnnularSectorWithLongitudeCrossed180;
import com.ict.ms.trackPlayBack.facade.common.CircularSectorWithLongitudeCrossed180;
import com.ict.ms.trackPlayBack.facade.common.IFInArea;
import com.ict.ms.trackPlayBack.facade.common.PolygonWithLongitudeCrossed180;
import com.ict.ms.trackPlayBack.service.dao.IHistoryServiceDao;
import com.ict.ms.trackPlayBack.facade.dto.AreaParams;
import com.ict.ms.trackPlayBack.facade.dto.Circular;
import com.ict.ms.trackPlayBack.facade.dto.CircularSector;
import com.ict.ms.trackPlayBack.facade.dto.ResultObjWithCount;
import com.ict.ms.trackPlayBack.facade.model.AreaPlayBack;
import com.ict.ms.trackPlayBack.facade.model.MapFusePlayBackList;
import com.ict.ms.trackPlayBack.facade.model.MapOrigPlayBackList;
import com.ict.ms.trackPlayBack.facade.api.IHistoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("historyService")
public class HistoryService implements IHistoryService{
    @Resource
    IHistoryServiceDao iHistoryServiceDao;

    private int MaxShow=5000;//态势回放最大返回点的数量，区域内点数量超过此值时返回目标数量过大信息

    /**
     * 矩形区域态势回放
     * @param hisAreaParams
     * @return
     */
    public ResultObjWithCount getHistoryDegInfo(AreaParams hisAreaParams, int mode){
        ResultObjWithCount resultObjWithCount=new ResultObjWithCount();

        String tid;
            List<AreaPlayBack> areaPlayBackList=null;
            if(mode==0){
                try{
                    if(hisAreaParams.getLim()<1){
                        areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfoNotLimit(hisAreaParams);
                    }else{
                        areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfo(hisAreaParams);
                    }

                    //点的数量
                    resultObjWithCount.setPointcount(areaPlayBackList.size());

                    if(areaPlayBackList.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }else {
                        Map<String, ArrayList<AreaPlayBack>> map = new HashMap<String, ArrayList<AreaPlayBack>>();
                        for (int i = 0; i < areaPlayBackList.size(); i++) {
                            //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                            tid = areaPlayBackList.get(i).getTid() + "";
                            AreaPlayBack areaPlayBack = areaPlayBackList.get(i);

                            putFuseAdd(map, tid, areaPlayBack);
                        }

                        List<MapFusePlayBackList> mapPlayBackLists = new ArrayList<MapFusePlayBackList>();
                        for (Map.Entry<String, ArrayList<AreaPlayBack>> entry : map.entrySet()) {
                            MapFusePlayBackList mapPlayBackList = new MapFusePlayBackList();
                            mapPlayBackList.setNum(Integer.parseInt(entry.getKey()));
                            mapPlayBackList.setPosList(entry.getValue());
                            mapPlayBackLists.add(mapPlayBackList);
                        }

                        resultObjWithCount.setShipcount(mapPlayBackLists.size());
                        resultObjWithCount.setState(1);
                        resultObjWithCount.setObj(mapPlayBackLists);
                        return resultObjWithCount;
                }}catch (Exception e){
                    System.out.println("数据库操作失败："+e);
                    resultObjWithCount.setState(-1);
                    return resultObjWithCount;
                }
            }else if(mode==1){
                try{
                    if (hisAreaParams.getLim()<1){
                        areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfoNotLimit(hisAreaParams);
                    }else {
                        areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfo(hisAreaParams);
                    }

                    //点的数量
                    resultObjWithCount.setPointcount(areaPlayBackList.size());

                    if(areaPlayBackList.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }
                    else if(areaPlayBackList.size()>MaxShow){
                        resultObjWithCount.setState(99);
                        return resultObjWithCount;
                    }
                    else{
                    Map<String,ArrayList<AreaPlayBack>> map=new HashMap<String,ArrayList<AreaPlayBack>>();

                    for (int i=0;i<areaPlayBackList.size();i++){
                        //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                        tid=areaPlayBackList.get(i).getTid()+"";
                        AreaPlayBack areaPlayBack=areaPlayBackList.get(i);

                        putOrigAdd(map,tid,areaPlayBack);
                    }

                    List<MapOrigPlayBackList> mapOrigPlayBackLists=new ArrayList<MapOrigPlayBackList>();
                    for(Map.Entry<String,ArrayList<AreaPlayBack>> entry:map.entrySet()){
                        MapOrigPlayBackList mapOrigPlayBackList=new MapOrigPlayBackList();

                        //原始模式将目标
                        String[] strArray=entry.getKey().split("_");
                        mapOrigPlayBackList.setNum(Integer.parseInt(strArray[0]));
                        mapOrigPlayBackList.setOrigtype(Integer.parseInt(strArray[1]));
                        mapOrigPlayBackList.setOrigSource(Integer.parseInt(strArray[2]));

                        mapOrigPlayBackList.setPosList(entry.getValue());
                        mapOrigPlayBackLists.add(mapOrigPlayBackList);
                    }

                    resultObjWithCount.setShipcount(mapOrigPlayBackLists.size());
                    resultObjWithCount.setState(1);
                    resultObjWithCount.setObj(mapOrigPlayBackLists);
                    return resultObjWithCount;
                    }
                }catch (Exception e){
                    System.out.println("数据库操作失败："+e);
                    resultObjWithCount.setState(-1);
                    return resultObjWithCount;
                }
            }
            else{
                resultObjWithCount.setState(-2);
                return resultObjWithCount;
            }
    }

    /**
     * 圆形区域态势回放-mysql版本
     * @param hisAreaParams 该圆形的外切矩形
     * @param circular 圆形对象
     * @return
     */
    public ResultObjWithCount hisPlayBackCircular(int mode,AreaParams hisAreaParams, Circular circular){
        ResultObjWithCount resultObjWithCount=new ResultObjWithCount();
        String tid;
        List<AreaPlayBack> areaPlayBackList;
        if(mode==0){
            try{
                if (hisAreaParams.getLim()<1){
                    areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfoNotLimit(hisAreaParams);
                }else {
                    areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfo(hisAreaParams);
                }

                //点的数量
                resultObjWithCount.setPointcount(areaPlayBackList.size());

                if(areaPlayBackList.size()==0){
                    resultObjWithCount.setState(0);
                    return resultObjWithCount;
                }else {
//==============//  此处对不在圆形区域内的点进行剔除List
                    List<AreaPlayBack> areaPlayBackListCircular=new ArrayList<AreaPlayBack>();
                    boolean ifSuc;
                    for(int i=0;i<areaPlayBackList.size();i++){
//                    System.out.println("获取到目标"+areaPlayBackListOrig.get(i).getTid()+"未除以600000的目标"+areaPlayBackListOrig.get(i).getTid()+"的经度为："+areaPlayBackListOrig.get(i).getLo()+",纬度为："+areaPlayBackListOrig.get(i).getLa());
                        ifSuc= IFInArea.ifInCircular(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),circular);
                        //在圆形区域内就加入新的列表
                        if(ifSuc){
                            areaPlayBackListCircular.add(areaPlayBackList.get(i));
                        }
                    }
                    if(areaPlayBackListCircular.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }
                    else if(areaPlayBackListCircular.size()>MaxShow){
                        resultObjWithCount.setState(99);
                        return resultObjWithCount;
                    }
                    else {
//==============//  此处对不在圆形区域内的点进行剔除List

                        Map<String, ArrayList<AreaPlayBack>> map = new HashMap<String, ArrayList<AreaPlayBack>>();
                        for (int i = 0; i < areaPlayBackListCircular.size(); i++) {
                            //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                            tid = areaPlayBackListCircular.get(i).getTid() + "";
                            AreaPlayBack areaPlayBack = areaPlayBackListCircular.get(i);

                            putFuseAdd(map, tid, areaPlayBack);
                        }

                        List<MapFusePlayBackList> mapPlayBackLists = new ArrayList<MapFusePlayBackList>();
                        for (Map.Entry<String, ArrayList<AreaPlayBack>> entry : map.entrySet()) {
                            MapFusePlayBackList mapPlayBackList = new MapFusePlayBackList();
                            mapPlayBackList.setNum(Integer.parseInt(entry.getKey()));
                            mapPlayBackList.setPosList(entry.getValue());
                            mapPlayBackLists.add(mapPlayBackList);
                        }

                        resultObjWithCount.setShipcount(mapPlayBackLists.size());
                        resultObjWithCount.setState(1);
                        resultObjWithCount.setObj(mapPlayBackLists);
                        return resultObjWithCount;
                    }
                }}catch (Exception e){
                System.out.println("数据库操作失败："+e);
                resultObjWithCount.setState(-1);
                return resultObjWithCount;
            }
        }else if(mode==1){
            try{
                if (hisAreaParams.getLim()<1){
                    areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfoNotLimit(hisAreaParams);
                }else {
                    areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfo(hisAreaParams);
                }

                //点的数量
                resultObjWithCount.setPointcount(areaPlayBackList.size());

                if(areaPlayBackList.size()==0){
                    resultObjWithCount.setState(0);
                    return resultObjWithCount;
                }else{
                    //==============//  此处对不在圆形区域内的点进行剔除List
                    List<AreaPlayBack> areaPlayBackListCircular=new ArrayList<AreaPlayBack>();
                    boolean ifSuc;
                    for(int i=0;i<areaPlayBackList.size();i++){
//                    System.out.println("获取到目标"+areaPlayBackListOrig.get(i).getTid()+"未除以600000的目标"+areaPlayBackListOrig.get(i).getTid()+"的经度为："+areaPlayBackListOrig.get(i).getLo()+",纬度为："+areaPlayBackListOrig.get(i).getLa());
                        ifSuc=IFInArea.ifInCircular(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),circular);
                        //在圆形区域内就加入新的列表
                        if(ifSuc){
                            areaPlayBackListCircular.add(areaPlayBackList.get(i));
                        }
                    }
                    if(areaPlayBackListCircular.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }
                    else if(areaPlayBackListCircular.size()>MaxShow){
                        resultObjWithCount.setState(99);
                        return resultObjWithCount;
                    }
                    else {
//==============//  此处对不在圆形区域内的点进行剔除List

                        Map<String,ArrayList<AreaPlayBack>> map=new HashMap<String,ArrayList<AreaPlayBack>>();

                        for (int i=0;i<areaPlayBackListCircular.size();i++){
                            //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                            tid=areaPlayBackListCircular.get(i).getTid()+"";
                            AreaPlayBack areaPlayBack=areaPlayBackListCircular.get(i);

                            putOrigAdd(map,tid,areaPlayBack);
                        }

                        List<MapOrigPlayBackList> mapOrigPlayBackLists=new ArrayList<MapOrigPlayBackList>();
                        for(Map.Entry<String,ArrayList<AreaPlayBack>> entry:map.entrySet()){
                            MapOrigPlayBackList mapOrigPlayBackList=new MapOrigPlayBackList();

                            //原始模式将目标
                            String[] strArray=entry.getKey().split("_");
                            mapOrigPlayBackList.setNum(Integer.parseInt(strArray[0]));
                            mapOrigPlayBackList.setOrigtype(Integer.parseInt(strArray[1]));
                            mapOrigPlayBackList.setOrigSource(Integer.parseInt(strArray[2]));

                            mapOrigPlayBackList.setPosList(entry.getValue());
                            mapOrigPlayBackLists.add(mapOrigPlayBackList);
                        }

                        resultObjWithCount.setShipcount(mapOrigPlayBackLists.size());
                        resultObjWithCount.setState(1);
                        resultObjWithCount.setObj(mapOrigPlayBackLists);
                        return resultObjWithCount;
                    }
                }
            }catch (Exception e){
                System.out.println("数据库操作失败："+e);
                resultObjWithCount.setState(-1);
                return resultObjWithCount;
            }
        }
        else{
            resultObjWithCount.setState(-2);
            return resultObjWithCount;
        }
    }

    /**
     * 扇（环）形区域态势回放
     * @param mode
     * @param hisAreaParams
     * @param circularSector
     * @return
     */
    public ResultObjWithCount hisPlayBackSector(int mode,AreaParams hisAreaParams,CircularSector circularSector){
        ResultObjWithCount resultObjWithCount=new ResultObjWithCount();
        String tid;
        List<AreaPlayBack> areaPlayBackList;

//        if (circularSector.getRidius()==circularSector.getRidsaml()||circularSector.getRidsaml()==-1){
//            System.out.println("扇形中心点Lon："+circularSector.getCirlon()+",Lat："+circularSector.getCirlat()+",半径："+circularSector.getRidius()+",起始度数："+circularSector.getStartDeg()+",结束度数："+circularSector.getEndDeg());
//        }else {
//            System.out.println("扇环形中心点Lon："+circularSector.getCirlon()+",Lat："+circularSector.getCirlat()+",半径："+circularSector.getRidius()+",起始度数："+circularSector.getStartDeg()+",结束度数："+circularSector.getEndDeg()+",短半径："+circularSector.getRidsaml());
//        }

        if(mode==0){
            try{
                if (hisAreaParams.getLim()<1){
                    areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfoNotLimit(hisAreaParams);
                }else {
                    areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfo(hisAreaParams);
                }

                //点的数量
                resultObjWithCount.setPointcount(areaPlayBackList.size());

                if(areaPlayBackList.size()==0){
                    resultObjWithCount.setState(0);
                    return resultObjWithCount;
                }else {
//==============//  此处对不在圆形区域内出现过的点进行剔除List
                    List<AreaPlayBack> areaPlayBackListCircular=new ArrayList<AreaPlayBack>();
                    boolean ifSuc;
                    for(int i=0;i<areaPlayBackList.size();i++){
//                    System.out.println("获取到目标"+areaPlayBackListOrig.get(i).getTid()+"未除以600000的目标"+areaPlayBackListOrig.get(i).getTid()+"的经度为："+areaPlayBackListOrig.get(i).getLo()+",纬度为："+areaPlayBackListOrig.get(i).getLa());
                        if (circularSector.getRidius()==circularSector.getRidsaml()||circularSector.getRidsaml()==-1){
                            CircularSectorWithLongitudeCrossed180 cir=new CircularSectorWithLongitudeCrossed180(circularSector.getCirlon(),circularSector.getCirlat(),circularSector.getRidius(),circularSector.getStartDeg(),circularSector.getEndDeg());
                            ifSuc=IFInArea.ifInSectorCircular(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),cir);
                        }else {
                            AnnularSectorWithLongitudeCrossed180 cir=new AnnularSectorWithLongitudeCrossed180(circularSector.getCirlon(),circularSector.getCirlat(),circularSector.getRidius(),circularSector.getStartDeg(),circularSector.getEndDeg(),circularSector.getRidsaml());
                            ifSuc=IFInArea.ifInSectorAnnular(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),cir);
                        }

                        //在区域内就加入新的列表
                        if(ifSuc){
                            areaPlayBackListCircular.add(areaPlayBackList.get(i));
                        }
                    }

                    if(areaPlayBackListCircular.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }
                    else if(areaPlayBackListCircular.size()>MaxShow){
                        resultObjWithCount.setState(99);
                        return resultObjWithCount;
                    }
                    else {
//==============//  此处对不在圆形区域内出现过的点进行剔除List

                        Map<String, ArrayList<AreaPlayBack>> map = new HashMap<String, ArrayList<AreaPlayBack>>();
                        for (int i = 0; i < areaPlayBackListCircular.size(); i++) {
                            //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                            tid = areaPlayBackListCircular.get(i).getTid() + "";
                            AreaPlayBack areaPlayBack = areaPlayBackListCircular.get(i);

                            putFuseAdd(map, tid, areaPlayBack);
                        }

                        List<MapFusePlayBackList> mapPlayBackLists = new ArrayList<MapFusePlayBackList>();
                        for (Map.Entry<String, ArrayList<AreaPlayBack>> entry : map.entrySet()) {
                            MapFusePlayBackList mapPlayBackList = new MapFusePlayBackList();
                            mapPlayBackList.setNum(Integer.parseInt(entry.getKey()));
                            mapPlayBackList.setPosList(entry.getValue());
                            mapPlayBackLists.add(mapPlayBackList);
                        }

                        resultObjWithCount.setShipcount(mapPlayBackLists.size());
                        resultObjWithCount.setState(1);
                        resultObjWithCount.setObj(mapPlayBackLists);
                        return resultObjWithCount;
                    }
                }}catch (Exception e){
                System.out.println("数据库操作失败："+e);
                resultObjWithCount.setState(-1);
                return resultObjWithCount;
            }
        }else if(mode==1){
            try{
                if (hisAreaParams.getLim()<1){
                    areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfoNotLimit(hisAreaParams);
                }else {
                    areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfo(hisAreaParams);
                }

                //点的数量
                resultObjWithCount.setPointcount(areaPlayBackList.size());

                if(areaPlayBackList.size()==0){
                    resultObjWithCount.setState(0);
                    return resultObjWithCount;
                }else{
                    //==============//  此处对不在圆形区域内出现过的点进行剔除List
                    List<AreaPlayBack> areaPlayBackListCircular=new ArrayList<AreaPlayBack>();
                    boolean ifSuc;
                    for(int i=0;i<areaPlayBackList.size();i++){
                    System.out.println("获取到目标"+areaPlayBackList.get(i).getTid()+"未除以600000的目标"+areaPlayBackList.get(i).getTid()+"的经度为："+areaPlayBackList.get(i).getLo()+",纬度为："+areaPlayBackList.get(i).getLa());
                        if (circularSector.getRidius()==circularSector.getRidsaml()||circularSector.getRidsaml()==-1){
                            CircularSectorWithLongitudeCrossed180 cir=new CircularSectorWithLongitudeCrossed180(circularSector.getCirlon(),circularSector.getCirlat(),circularSector.getRidius(),circularSector.getStartDeg(),circularSector.getEndDeg());
                            ifSuc=IFInArea.ifInSectorCircular(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),cir);
                        }else {
                            AnnularSectorWithLongitudeCrossed180 cir=new AnnularSectorWithLongitudeCrossed180(circularSector.getCirlon(),circularSector.getCirlat(),circularSector.getRidius(),circularSector.getStartDeg(),circularSector.getEndDeg(),circularSector.getRidsaml());
                            ifSuc=IFInArea.ifInSectorAnnular(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),cir);
                        }
                        //在圆形区域内就加入新的列表
                        if(ifSuc){
                            areaPlayBackListCircular.add(areaPlayBackList.get(i));
                        }
                    }
                    if(areaPlayBackListCircular.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }
                    else if(areaPlayBackListCircular.size()>MaxShow){
                        resultObjWithCount.setState(99);
                        return resultObjWithCount;
                    }
                    else {
//==============//  此处对不在圆形区域内出现过的点进行剔除List

                        Map<String,ArrayList<AreaPlayBack>> map=new HashMap<String,ArrayList<AreaPlayBack>>();

                        for (int i=0;i<areaPlayBackListCircular.size();i++){
                            //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                            tid=areaPlayBackListCircular.get(i).getTid()+"";
                            AreaPlayBack areaPlayBack=areaPlayBackListCircular.get(i);

                            putOrigAdd(map,tid,areaPlayBack);
                        }

                        List<MapOrigPlayBackList> mapOrigPlayBackLists=new ArrayList<MapOrigPlayBackList>();
                        for(Map.Entry<String,ArrayList<AreaPlayBack>> entry:map.entrySet()){
                            MapOrigPlayBackList mapOrigPlayBackList=new MapOrigPlayBackList();

                            //原始模式将目标
                            String[] strArray=entry.getKey().split("_");
                            mapOrigPlayBackList.setNum(Integer.parseInt(strArray[0]));
                            mapOrigPlayBackList.setOrigtype(Integer.parseInt(strArray[1]));
                            mapOrigPlayBackList.setOrigSource(Integer.parseInt(strArray[2]));

                            mapOrigPlayBackList.setPosList(entry.getValue());
                            mapOrigPlayBackLists.add(mapOrigPlayBackList);
                        }

                        resultObjWithCount.setShipcount(mapOrigPlayBackLists.size());
                        resultObjWithCount.setState(1);
                        resultObjWithCount.setObj(mapOrigPlayBackLists);
                        return resultObjWithCount;
                    }
                }
            }catch (Exception e){
                System.out.println("数据库操作失败："+e);
                resultObjWithCount.setState(-1);
                return resultObjWithCount;
            }
        }
        else{
            resultObjWithCount.setState(-2);
            return resultObjWithCount;
        }
    }

    /**
     * 多边形区域态势回放
     * @param mode
     * @param hisAreaParams
     * @return
     */
    public ResultObjWithCount hisPlayBackPolygons(int mode,AreaParams hisAreaParams, ArrayList<Double> point_x_list,ArrayList<Double> point_y_list){
        ResultObjWithCount resultObjWithCount=new ResultObjWithCount();
        String tid;

        PolygonWithLongitudeCrossed180 p = new PolygonWithLongitudeCrossed180(point_x_list,point_y_list);

        List<AreaPlayBack> areaPlayBackList;
        if(mode==0){
            try{
                if (hisAreaParams.getLim()<1){
                    areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfoNotLimit(hisAreaParams);
                }else {
                    areaPlayBackList=iHistoryServiceDao.getFuseHistoryDegInfo(hisAreaParams);
                }

                //点的数量
                resultObjWithCount.setPointcount(areaPlayBackList.size());

                if(areaPlayBackList.size()==0){
                    resultObjWithCount.setState(0);
                    return resultObjWithCount;
                }else {
//==============//  此处对不在多边形区域内的点进行剔除List
                    List<AreaPlayBack> areaPlayBackListPolygons=new ArrayList<AreaPlayBack>();
                    boolean ifSuc;
                    for(int i=0;i<areaPlayBackList.size();i++){
//                    System.out.println("获取到目标"+areaPlayBackListOrig.get(i).getTid()+"未除以600000的目标"+areaPlayBackListOrig.get(i).getTid()+"的经度为："+areaPlayBackListOrig.get(i).getLo()+",纬度为："+areaPlayBackListOrig.get(i).getLa());
                        ifSuc=IFInArea.ifInPolygons(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),p);
                        //在圆形区域内就加入新的列表
                        if(ifSuc){
                            areaPlayBackListPolygons.add(areaPlayBackList.get(i));
                        }
                    }
                    if(areaPlayBackListPolygons.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }
                    else if(areaPlayBackListPolygons.size()>MaxShow){
                        resultObjWithCount.setState(99);
                        return resultObjWithCount;
                    }
                    else {
//==============//  此处对不在圆形区域内的点进行剔除List

                        Map<String, ArrayList<AreaPlayBack>> map = new HashMap<String, ArrayList<AreaPlayBack>>();
                        for (int i = 0; i < areaPlayBackListPolygons.size(); i++) {
                            //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                            tid = areaPlayBackListPolygons.get(i).getTid() + "";
                            AreaPlayBack areaPlayBack = areaPlayBackListPolygons.get(i);

                            putFuseAdd(map, tid, areaPlayBack);
                        }

                        List<MapFusePlayBackList> mapPlayBackLists = new ArrayList<MapFusePlayBackList>();
                        for (Map.Entry<String, ArrayList<AreaPlayBack>> entry : map.entrySet()) {
                            MapFusePlayBackList mapPlayBackList = new MapFusePlayBackList();
                            mapPlayBackList.setNum(Integer.parseInt(entry.getKey()));
                            mapPlayBackList.setPosList(entry.getValue());
                            mapPlayBackLists.add(mapPlayBackList);
                        }

                        resultObjWithCount.setShipcount(mapPlayBackLists.size());
                        resultObjWithCount.setState(1);
                        resultObjWithCount.setObj(mapPlayBackLists);
                        return resultObjWithCount;
                    }
                }}catch (Exception e){
                System.out.println("数据库操作失败："+e);
                resultObjWithCount.setState(-1);
                return resultObjWithCount;
            }
        }else if(mode==1){
            try{
                if (hisAreaParams.getLim()<1){
                    areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfoNotLimit(hisAreaParams);
                }else {
                    areaPlayBackList=iHistoryServiceDao.getOrigHistoryDegInfo(hisAreaParams);
                }

                //点的数量
                resultObjWithCount.setPointcount(areaPlayBackList.size());

                if(areaPlayBackList.size()==0){
                    resultObjWithCount.setState(0);
                    return resultObjWithCount;
                }else{
                    //==============//  此处对不在圆形区域内的点进行剔除List
                    List<AreaPlayBack> areaPlayBackListPolygons=new ArrayList<AreaPlayBack>();
                    boolean ifSuc;
                    for(int i=0;i<areaPlayBackList.size();i++){
//                    System.out.println("获取到目标"+areaPlayBackListOrig.get(i).getTid()+"未除以600000的目标"+areaPlayBackListOrig.get(i).getTid()+"的经度为："+areaPlayBackListOrig.get(i).getLo()+",纬度为："+areaPlayBackListOrig.get(i).getLa());
                        ifSuc=IFInArea.ifInPolygons(areaPlayBackList.get(i).getLo(),areaPlayBackList.get(i).getLa(),p);
                        //在圆形区域内就加入新的列表
                        if(ifSuc){
                            areaPlayBackListPolygons.add(areaPlayBackList.get(i));
                        }
                    }
                    if(areaPlayBackListPolygons.size()==0){
                        resultObjWithCount.setState(0);
                        return resultObjWithCount;
                    }
                    else if(areaPlayBackListPolygons.size()>MaxShow){
                        resultObjWithCount.setState(99);
                        return resultObjWithCount;
                    }
                    else {
//==============//  此处对不在圆形区域内的点进行剔除List
                        Map<String,ArrayList<AreaPlayBack>> map=new HashMap<String,ArrayList<AreaPlayBack>>();

                        for (int i=0;i<areaPlayBackListPolygons.size();i++){
                            //调用该方法对列表里面的目标进行指定目标生成对应列表分类
                            tid=areaPlayBackListPolygons.get(i).getTid()+"";
                            AreaPlayBack areaPlayBack=areaPlayBackListPolygons.get(i);

                            putOrigAdd(map,tid,areaPlayBack);
                        }

                        List<MapOrigPlayBackList> mapOrigPlayBackLists=new ArrayList<MapOrigPlayBackList>();
                        for(Map.Entry<String,ArrayList<AreaPlayBack>> entry:map.entrySet()){
                            MapOrigPlayBackList mapOrigPlayBackList=new MapOrigPlayBackList();

                            //原始模式将目标
                            String[] strArray=entry.getKey().split("_");
                            mapOrigPlayBackList.setNum(Integer.parseInt(strArray[0]));
                            mapOrigPlayBackList.setOrigtype(Integer.parseInt(strArray[1]));
                            mapOrigPlayBackList.setOrigSource(Integer.parseInt(strArray[2]));

                            mapOrigPlayBackList.setPosList(entry.getValue());
                            mapOrigPlayBackLists.add(mapOrigPlayBackList);
                        }

                        resultObjWithCount.setShipcount(mapOrigPlayBackLists.size());
                        resultObjWithCount.setState(1);
                        resultObjWithCount.setObj(mapOrigPlayBackLists);
                        return resultObjWithCount;
                    }
                }
            }catch (Exception e){
                System.out.println("数据库操作失败："+e);
                resultObjWithCount.setState(-1);
                return resultObjWithCount;
            }
        }
        else{
            resultObjWithCount.setState(-2);
            return resultObjWithCount;
        }
    }

    /**
     * 原始模式对指定列表进行唯一标识列表分类方法
     * @param map
     * @param key
     * @param areaPlayBack
     */
    public void putFuseAdd(Map<String,ArrayList<AreaPlayBack>> map, String key, AreaPlayBack areaPlayBack){
        if(!map.containsKey(key)){
            map.put(key, new ArrayList<AreaPlayBack>());
        }
        map.get(key).add(areaPlayBack);
    }

    /**
     * 原始模式对指定列表进行唯一标识列表分类方法
     * @param map
     * @param key
     * @param areaPlayBack
     */
    public void putOrigAdd(Map<String,ArrayList<AreaPlayBack>> map, String key, AreaPlayBack areaPlayBack){
        key=key+"_"+areaPlayBack.getTp()+"_"+areaPlayBack.getSo();
        if(!map.containsKey(key)){
            map.put(key, new ArrayList<AreaPlayBack>());
        }
        map.get(key).add(areaPlayBack);
    }
}